from collections import deque


class MinStack:
    def __init__(self):
        self.s1, self.s2 = deque(), deque()
        self.min = float('inf')

    def push(self, num):
        self.s1.append(num)
        if num <= self.min:
            self.min = num
            self.s2.append(self.min)

    def pop(self):
        if not self.s1:
            raise Exception('栈为空')
        res = self.s1.pop()
        if res == self.min:
            self.s2.pop()
            self.min = self.s2[-1] if self.s2 else float('inf')

    def get_min(self):
        if not self.s2:
            raise Exception('栈为空')
        return self.s2[-1]


min_stack = MinStack()
min_stack.push(2)
min_stack.push(4)
min_stack.push(5)
min_stack.push(1)
min_stack.push(3)
min_stack.pop()
min_stack.pop()
min_stack.pop()
min_stack.pop()
min_stack.pop()
print(min_stack.get_min())
